
<%var csstpl = {%>
    <link href="${basepath}/vendor/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link rel="stylesheet" href="${basepath}/vendor/js/plugins/fancybox/jquery.fancybox.css" />
    <style>
    	
    	.page_action { text-align:right; }
    	.page_action .span8 { margin:-20px 0; }
    	.page_action .dataTables_info { padding:20px 0; float:left; }
    	.page_action .dataTables_paginate { padding:0; height:30px !important; }
    	.ibox-content { padding:15px; }
    	.btn_reload { color:#fff !important; }
    	table { margin:-10px 0 0 !important; }
    	.table>thead>tr>th { border-top:none; }
    	
    	.search_panel { position:relative; margin-bottom:20px; padding:15px; background:#fff; border: 1px solid #e7eaec; border-radius:3px; }
    	.search_panel .part1 label  { position:relative; display:block; width:300px; margin:10px 0; padding:6px; }
    	.search_panel .part1 input  { position:absolute; left:100px; top:0px; width:150px; padding:6px; font:13px/15px "微软雅黑"; border:1px solid #ddd; border-radius:3px; }
    	.search_panel .part1 select { position:absolute; left:100px; top:0px; width:150px; padding:5px; font:12px/15px "微软雅黑"; border:1px solid #ddd; border-radius:3px; }
    	.search_panel .btns { padding:10px 0 0 100px; }
    	.search_panel .btns .btn.color { font:13px/20px "微软雅黑"; margin-right:5px; padding:3px 20px; background:#1AB394; color:#fff; border:1px solid #1AB394; }
    	.search_panel .btns .btn.line  { font:13px/20px "微软雅黑"; margin-right:5px; padding:3px 20px; background:#ffffff; color:#333; border:1px solid #ddd; }
    	
    	.input-group select { width:150px; padding:5px; font:12px/15px "微软雅黑"; border:1px solid #ddd; border-radius:3px; }
    	
    	.empty { height:400px; background:url("${basepath}/vendor/img/list_empty.png") no-repeat center; }

    </style>
<%};%>
<%var jstpl = {%>
    <script src="${basepath}/plugin/clipboard.min.js"></script>
    <script src="${basepath}/vendor/js/plugins/fancybox/jquery.fancybox.js"></script>
    <script>
    	$(document).ready(function(){
    		clip = new Clipboard(".link");
    		clip.on("success",function(e){ layer.msg("复制成功！"); });
    		clip.on("error",function(e){ layer.msg("复制失败，请重试！"); });
    		//fancy插件 - 查看商品图片
    		$(".fancy").fancybox({
				padding:8,
				openEffect:"none",
				closeEffect:"none"
			});
			$(".btn_examine").click(function(){
				var productid =  $(this).data("productid");
				gx.win("商品审核","/system/product/edit/"+productid+"?view_type=examine",['1224px','868px'])
			})
    	});
    	function preview_view(id){
    		gx.iframeindex=layer.open({
    		    type: 2,
    		    title: "商品预览",
    		    shadeClose: true,
    	        shade: false,
    	        maxmin: false, 
    		    shade: 0.8,
    		    area: ['375px ','627px'],
    		    content: "${wxpath!}/wx/products/detail/"+id+"?t=view"
    		}); 
    	}
    </script>
<%};%>
<%layout("../layout/_layout_mall.html",{title:'商品列表',jstpl:jstpl,csstpl:csstpl}){ %>
    <div class="wrapper wrapper-content animated fadeInUp">
    <form type="post" action="/system/product" >
    
    	<!-- 搜索面板 -->
    	<div class="search_panel">
    		<div class="part1">
    		  <label>商品名称：<input type="text" value="${product.product_name!}" name="product.product_name" /></label>
    		  <label>商品类型：<#select attr='  id="type_id"   name="product.type_id"     '  value="${product.type_id!+''}"  listdata="${product_type!}" text="type_name" key="id" /></label>
    		  <label>上下架：<#select attr=' id="online_state" name="product.online_state" ' value="${product.online_state!+''}" listdata="${@AppConst.Pro_State}" /></label>
    		 <label>销售类型：
    		 <#select  
				attr="data-rule name='product.attr_type'  class='span12' "   
				value="${product.attr_type!+''}"
				listdata="${@AppConst.Product_Attr_Type}" 
				headkey="0"
				headtext="请选择销售类型"
				 />
    		  </label>
    		</div>
    		<div class="btns">
    		  <button type="submit" class="btn color btn-primary"> 搜索</button>
    		</div>
    		<!--  </form>  -->
    	</div>
    
    
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-title">
                        <h5>所有商品列表</h5>
                        <div class="ibox-tools">
                            <a href="javascript:location.reload();" class="btn btn-warning btn-xs btn_reload"><i class="fa fa-refresh"></i> 刷新</a>
                            <%if(user_type==-1 || user_type==11){%>
                            <a href="/system/product/add" class="btn btn-primary btn-xs">创建新商品</a>
                            <%}%>
                        </div>
                    </div>
                   
                     
                    <div class="ibox-content">
                       
                        <div class="project-list">

                            <table class="table table-hover" style="margin-top:25px;">
							<tbody id="type">
								<thead>
                                     <tr>
                                     <th style="width:45px">编号</th>
                                     <th style="width:70px">图片</th>
                                     <th>名称  </th>
                                     <th>上架 </th>
                                     <th>销售类型</th>
                                     <th>PV</th>
                                     <th>审核状态</th>
                                     <th>原始积分</th>
                                     <th>创建时间 </th>
                                     <th style="width:330px;">操作 </th>
                                     </tr>
                                </thead>
                                
                                <% for(product in data.list){  %>
                                <tr>
                                    <td>${product.id}</td>
                                    <td class="project-people" style="text-align:center;">
                                            <a href="${product.image_center!'/static/vendor/wz/img/fmdtp.jpg'}" class="fancy"><img alt="image" src="${product.image_center!'/static/vendor/wz/img/fmdtp.jpg'}" style="border-radius:3px;"></a>
                                    </td>
									<td class="project-title t1">${product.product_name!}
										<%if(product.online_state==3){%>
										 <button  type="button" data-productid="${product.id!}" class="btn btn-primary btn-outline btn-sm btn_examine"><i class="fa fa-pencil"></i> 审核上线 </button>
										<%}%>
									</td>
									<td class="project-title t1">
									  <% if(product.online_state==1){ %>
									  <span class="label label-success">上架 </span>
									  <%  }else if(product.online_state==2) { %>
									  <span class="label label-danger">未上架 </span>
									  <%  }  %>
									</td>
	  								<td class="project-title t1">
	  									<span class="label label-info">${@AppConst.Product_Attr_Type.get(product.attr_type+'')}</span>
	  								</td>
									<td class="project-title t1">${product.product_pv!0}</td>
                                    <td class="project-title t1">
                                        <% if(product.examine_state==1){ %>
                                        <span class="label label-success">审核通过 </span>
                                        <%  }else if(product.examine_state==2) { %>
                                        <span class="label label-danger">审核失败</span><br/>
                                        <code>失败原因：${product.fail_reason!}</code>
                                        <%  }else if(product.examine_state==0){  %>
                                        <span class="label ">待审核 </span>
                                        <%}%>
                                    </td>
                                    <td>${product.integral!}</td>
									<td><small>${product.createtime!,"yyyy-MM-dd HH:mm:ss"}</small></td>
									<td class="project-actions">
                                    <%if(user_type==-1){%>
                                        <a id="edit1" href="/system/product/edit/${product.id!}" class="btn btn-warning btn-outline btn-sm edit"><i class="fa fa-pencil"></i> 编辑 </a>
                                        <a id="search1" href="javascript:gx.del('/system/product/delete/${product.id!}')" class="btn btn-primary btn-outline btn-sm"><i class="fa fa-trash"></i> 删除 </a>
                                        <%if(product.examine_state==0){%>
                                        <a  href="javascript:;" class="btn btn-primary btn-outline btn-sm tg" data-id="${product.id!}">  通过 </a>
                                        <a  href="javascript:;" class="btn btn-primary btn-outline btn-sm jj" data-id="${product.id!}">  拒绝 </a>
                                        <%}%>
                                    <%}else if(user_type==11){%>
                                        <a id="edit1" href="/system/product/edit/${product.id!}" class="btn btn-warning btn-outline btn-sm edit"><i class="fa fa-pencil"></i> 编辑 </a>
                                    <%}else if(user_type==12){%>
                                        <%if(product.examine_state==0){%>
                                        <a  href="javascript:;" class="btn btn-primary btn-outline btn-sm tg" data-id="${product.id!}">  通过 </a>
                                        <a  href="javascript:;" class="btn btn-primary btn-outline btn-sm jj" data-id="${product.id!}">  拒绝 </a>
                                        <%}%>
                                        <a   href="/system/product/select/${product.id!}" class="btn btn-warning btn-outline btn-sm edit">查看</a>
                                        <a id="search1" href="javascript:gx.del('/system/product/delete/${product.id!}')" class="btn btn-primary btn-outline btn-sm"><i class="fa fa-trash"></i> 删除 </a>
                                    <%}%>
									</td>
								</tr>
                                <%  }   %>
							</tbody>
                                </table>
                                <% if(isEmpty(data.list)){ %>
                            <div class="empty"></div>
                            <% } %>
                            </div>
                            
                        </div>
                        <div class="page_action">
                        <%include("/jsp/_paginate_mall.html"){}%>
                        </div>
                     
                    </div>
                </div>
            </div>
        
        </form>
        </div>
<%}%>
<script>
$(function(){
	 //alert(88);
	$("#loading-example-btn").click(function(){
		window.location.reload();
	});

    $(".tg").on("click",function () {
        var id =$(this).data("id");
        gx.confirm("您是否确定进行此操作？",function () {
            Ajax("/system/product/through",{'id':id},function (ret) {
                if(ret.state){
                    gx.alerts(ret.msg,function () {
                        window.location.reload();
                    })
                }else{
                    gx.alert(ret.msg);
                }
            })
        })
    })

    $(".jj").on("click",function () {
        var id =$(this).data("id");
        layer.prompt({
            formType: 2,
            title: '请输入拒绝理由',
            maxlength: 50,
        }, function(value, index, elem){
            if(value==null || value==""){
                layer.msg("拒绝理由不能为空！");
                return ;
            }
            Ajax("/system/product/refuse",{'id':id,'reason':value},function(d){
                if(d.state){
                    gx.alerts(d.msg,function () {
                        window.location.reload();
                    })
                }else{
                    gx.alert(d.msg);
                }
            })

        })
    })
})

function  AddLottery(pro_id){
	gx.ajax("/system/product/add_lottery?pro_id="+pro_id,function(d){
		gx.toast("随机中奖人员成功！");
	})
}

</script>